import { Context, Application } from 'egg'
import { BizConfig } from '../../config/config.default'

export default (options: BizConfig['globalOptions'], app: Application) => {
  app.logger.info('global middleware app/middleware/global.js')

  return async (ctx: Context, next: () => Promise<any>) => {
    await next()
    if (!ctx.request.url.startsWith('/socket.io/') && !ctx.request.url.startsWith('/entity/')) {
      ctx.logger.info('%j %j %j %j %s %s',
        options,
        ctx.query,
        Object.keys(ctx.request.body || {}),
        ctx.params,
        ctx.status,
        // ctx.reponse.message,
        typeof ctx.body)
    }
  }
}
